Add gdk_gl_texture_quad() helper
authorAlexander Larsson <alexl@redhat.com>
Wed, 5 Nov 2014 14:42:06 +0000 (15:42 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 6 Nov 2014 11:24:43 +0000 (12:24 +0100)
Right now this just centralizes the glBegin/glEnd code, but
this will be replaced with buffer objects later.

gdk/gdkgl.c
gdk/gdkinternals.h
gdk/x11/gdkglcontext-x11.c

index c7c847a0fccc15c840f6b7c6055fec4273b787cc..f490330da7febfeacb97da88c46343c11baa4467 100644 (file)
@@ -35,6 +35,28 @@ gdk_cairo_surface_mark_as_direct (cairo_surface_t *surface,
                                g_object_ref (window),  g_object_unref);
 }
 
+void
+gdk_gl_texture_quad (float x1, float y1,
+                     float x2, float y2,
+                     float u1, float v1,
+                     float u2, float v2)
+{
+  glBegin (GL_QUADS);
+  glTexCoord2f (u1, v2);
+  glVertex2f (x1, y2);
+
+  glTexCoord2f (u2, v2);
+  glVertex2f (x2, y2);
+
+  glTexCoord2f (u2, v1);
+  glVertex2f (x2, y1);
+
+  glTexCoord2f (u1, v1);
+  glVertex2f (x1, y1);
+  glEnd();
+}
+
+
 /* x,y,width,height describes a rectangle in the gl render buffer
    coordinate space, and its top left corner is drawn at the current
    position according to the cairo translation. */
@@ -304,19 +326,10 @@ gdk_cairo_draw_from_gl (cairo_t              *cr,
               int clipped_src_x = x + (dest.x - dx * window_scale);
               int clipped_src_y = y + (height - dest.height - (dest.y - dy * window_scale));
 
-              glBegin (GL_QUADS);
-              glTexCoord2f (clipped_src_x / (float)texture_width, clipped_src_y / (float)texture_height);
-              glVertex2f (dest.x, FLIP_Y(dest.y + dest.height));
-
-              glTexCoord2f ((clipped_src_x + dest.width) / (float)texture_width, clipped_src_y / (float)texture_height);
-              glVertex2f (dest.x + dest.width, FLIP_Y(dest.y + dest.height));
-
-              glTexCoord2f ((clipped_src_x + dest.width) / (float)texture_width, (clipped_src_y + dest.height) / (float)texture_height);
-              glVertex2f (dest.x + dest.width, FLIP_Y(dest.y));
-
-              glTexCoord2f (clipped_src_x / (float)texture_width, (clipped_src_y + dest.height) / (float)texture_height);
-              glVertex2f (dest.x, FLIP_Y(dest.y));
-              glEnd();
+              gdk_gl_texture_quad (dest.x, FLIP_Y(dest.y),
+                                   dest.x + dest.width, FLIP_Y(dest.y + dest.height),
+                                   clipped_src_x / (float)texture_width, (clipped_src_y + dest.height) / (float)texture_height,
+                                   (clipped_src_x + dest.width) / (float)texture_width, clipped_src_y / (float)texture_height);
 
               if (impl_window->current_paint.flushed_region)
                 {
@@ -425,7 +438,6 @@ gdk_gl_texture_from_surface (cairo_surface_t *surface,
     return;
 
   /* Software fallback */
-
   use_texture_rectangle = gdk_gl_context_use_texture_rectangle (current);
 
   window = gdk_gl_context_get_window (current);
@@ -492,19 +504,10 @@ gdk_gl_texture_from_surface (cairo_surface_t *surface,
           vmax = 1.0;
         }
 
-      glBegin (GL_QUADS);
-      glTexCoord2f (0, vmax);
-      glVertex2f (rect.x * window_scale, FLIP_Y(rect.y + rect.height) * window_scale);
-
-      glTexCoord2f (umax, vmax);
-      glVertex2f ((rect.x + rect.width) * window_scale, FLIP_Y(rect.y + rect.height) * window_scale);
-
-      glTexCoord2f (umax, 0);
-      glVertex2f ((rect.x + rect.width) * window_scale, FLIP_Y(rect.y) * window_scale);
-
-      glTexCoord2f (0, 0);
-      glVertex2f (rect.x * window_scale, FLIP_Y(rect.y) * window_scale);
-      glEnd();
+      gdk_gl_texture_quad (rect.x * window_scale, FLIP_Y(rect.y) * window_scale,
+                           (rect.x + rect.width) * window_scale, FLIP_Y(rect.y + rect.height) * window_scale,
+                           0, 0,
+                           umax, vmax);
     }
 
   glDisable (target);
index bb7b71a97e5c2ebd935a72144192f2c9bfc947db..69be7047fef1af3f1e10d2bad3c02d7331505cf4 100644 (file)
@@ -341,6 +341,10 @@ gboolean        _gdk_cairo_surface_extents       (cairo_surface_t *surface,
                                                   GdkRectangle    *extents);
 void            gdk_gl_texture_from_surface      (cairo_surface_t *surface,
                                                   cairo_region_t  *region);
+void           gdk_gl_texture_quad               (float x1, float y1,
+                                                  float x2, float y2,
+                                                  float u1, float v1,
+                                                  float u2, float v2);
 void            gdk_cairo_surface_mark_as_direct (cairo_surface_t *surface,
                                                   GdkWindow       *window);
 cairo_region_t *gdk_cairo_region_from_clip       (cairo_t         *cr);
index bc48d4d7e8495acd0882c8a485a5df17444b9d4e..7b86a723bea7ec174f04e070d4ddfd586d9e10d5 100644 (file)
@@ -469,19 +469,10 @@ gdk_x11_gl_context_texture_from_surface (GdkGLContext *context,
           vscale = 1.0 / cairo_xlib_surface_get_height (surface);
         }
 
-      glBegin (GL_QUADS);
-      glTexCoord2f (uscale * src_x, vscale * (src_y + src_height));
-      glVertex2f (rect.x * window_scale, FLIP_Y(rect.y + rect.height) * window_scale);
-
-      glTexCoord2f (uscale * (src_x + src_width), vscale * (src_y + src_height));
-      glVertex2f ((rect.x + rect.width) * window_scale, FLIP_Y(rect.y + rect.height) * window_scale);
-
-      glTexCoord2f (uscale * (src_x + src_width), vscale * src_y);
-      glVertex2f ((rect.x + rect.width) * window_scale, FLIP_Y(rect.y) * window_scale);
-
-      glTexCoord2f (uscale * src_x, vscale * src_y);
-      glVertex2f (rect.x * window_scale, FLIP_Y(rect.y) * window_scale);
-      glEnd();
+      gdk_gl_texture_quad (rect.x * window_scale, FLIP_Y(rect.y) * window_scale,
+                           (rect.x + rect.width) * window_scale, FLIP_Y(rect.y + rect.height) * window_scale,
+                           uscale * src_x, vscale * src_y,
+                           uscale * (src_x + src_width), vscale * (src_y + src_height));
     }
 
   glXReleaseTexImageEXT (glx_pixmap->display, glx_pixmap->drawable,